//
//  ZKBaseTextField.m
//  FoodFreeApp
//
//  Created by 凯朱 on 2020/1/4.
//  Copyright © 2020 zhu2. All rights reserved.
//

#import "ZKBaseTextField.h"

@implementation ZKBaseTextField
- (void)awakeFromNib {
    [super awakeFromNib];
    
     self.inputAccessoryView = [self onKeyBoardFinishedButton];
}


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
       
        self.inputAccessoryView = [self onKeyBoardFinishedButton];
        
    }
    
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame delegate:(id<UITextFieldDelegate>)delegate{
    
    if (self = [super initWithFrame:frame]) {
        self.delegate = delegate;
        self.inputAccessoryView = [self onKeyBoardFinishedButton];
        
    }
    
    return self;
}

-(instancetype)init{
    
    if (self = [super init]) {
        self.inputAccessoryView = [self onKeyBoardFinishedButton];
    }
    
    return self;
}


/**
 *  @return 返回底视图
 */
-(UIView *)onKeyBoardFinishedButton
{
    CGSize size = [[UIScreen mainScreen] bounds].size;
    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, 40)];
    tempView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    
    //加条线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0.5, CGRectGetWidth(tempView.bounds), 0.5)];
    lineView.backgroundColor = KColor_Line;
    [tempView addSubview:lineView];
    
    UIButton *finishBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(tempView.bounds)-60, 5, 60, 30)];
    [finishBtn setTitle:@"完成" forState:UIControlStateNormal];
    [finishBtn addTarget:self action:@selector(onKeyBoardFinishedButton:) forControlEvents:UIControlEventTouchUpInside];
    [tempView addSubview:finishBtn];
    [finishBtn.titleLabel setFont:kFont(14)];
    [finishBtn setTitleColor:KColor_1 forState:UIControlStateNormal];
    
    return tempView;
}

-(void)onKeyBoardFinishedButton:(UIButton *)sender
{
     [self resignFirstResponder];
}


-(void)setPlaceholderWithPlaceholderText:(NSString *)holderText withColor:(UIColor *)color withFont:(UIFont *)font
{
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:holderText];
    [placeholder addAttribute:NSForegroundColorAttributeName
                        value:color
                        range:NSMakeRange(0, holderText.length)];
    [placeholder addAttribute:NSFontAttributeName
                        value:font
                        range:NSMakeRange(0, holderText.length)];
    self.attributedPlaceholder = placeholder;
}

@end
